package com.koo.modules.activiti.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.koo.common.utils.MyStrUtil;
import com.koo.modules.activiti.entity.WorkflowLeave;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;

import com.koo.modules.activiti.dao.WorkflowLeaveDao;
import com.koo.modules.activiti.entity.WorkflowLeaveEntity;
import com.koo.modules.activiti.service.WorkflowLeaveService;


@Service
public class WorkflowLeaveServiceImpl extends ServiceImpl<WorkflowLeaveDao, WorkflowLeaveEntity> implements WorkflowLeaveService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object dataForm = params.get("dataForm");
        WorkflowLeave workflowLeave = JSON.parseObject(JSON.toJSONString(dataForm), WorkflowLeave.class);
        Integer type = workflowLeave.getType();
        String title = workflowLeave.getTitle();

        LambdaQueryWrapper<WorkflowLeaveEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MyStrUtil.isNotEmpty(type), WorkflowLeaveEntity::getType, type).
                or().like(MyStrUtil.isNotEmpty(title), WorkflowLeaveEntity::getTitle, title);

        queryWrapper.orderByDesc(WorkflowLeaveEntity::getCreateTime);

        IPage<WorkflowLeaveEntity> page = this.page(
                new Query<WorkflowLeaveEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}